# src/response.py
from fastapi import HTTPException
from typing import Optional, Dict, Any

def success_response(data: Optional[Dict[str, Any]] = None, msg: str = "操作成功") -> Dict[str, Any]:
    """成功响应格式"""
    return {
        "code": 0,
        "data": data if data is not None else {},
        "msg": msg
    }

def error_response(code: int = 500, msg: str = "操作失败", data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    """错误响应格式"""
    return {
        "code": code,
        "data": data if data is not None else {},
        "msg": msg
    }

def http_error(status_code: int, detail: str) -> HTTPException:
    """抛出HTTP异常"""
    return HTTPException(status_code=status_code, detail=detail)